<?php

namespace addons\fastworker;

use app\common\library\Menu;
use think\Addons;
use think\Console;
use think\Loader;

/**
 * workerman开发助手插件
 */
class Fastworker extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     * @throws \think\Exception
     */
    public function install()
    {
        $menu = [
            [
                'name' => 'fastworker',
                'title' => 'Workerman助手',
                'icon' => 'fa fa-terminal',
                'sublist' => [
                    ['name' => 'fastworker/index', 'title' => 'FASTWORKER'],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete('fastworker');
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable('fastworker');
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable('fastworker');
        return true;
    }

    public function appInit()
    {
        Console::addDefaultCommands([
            'addons\\fastworker\\library\\command\\Server',
            'addons\\fastworker\\library\\command\\GatewayWorker',
            'addons\\fastworker\\library\\command\\Timer',
        ]);
        Loader::addNamespace('Workerman',
            ADDON_PATH . 'fastworker' . DS . 'library' . DS . 'workerman' . DS . 'workerman' . DS);
        Loader::addNamespace('GatewayWorker',
            ADDON_PATH . 'fastworker' . DS . 'library' . DS . 'workerman' . DS . 'gateway-worker' . DS . 'src' . DS);
    }

}
